﻿using System.Linq;
using System.Text.RegularExpressions;
using DevExpress.XtraRichEdit.API.Word;
using Sumen.Business;
using Sumen.Business.Data;
using Sumen.Library.Enum;
using Sumen.Library.Froms;

using Sumen.Business.Permission;
using Sumen.Model.Model;


namespace Sumen.GUI.Sales
{
    public partial class Frm_Sales_Return : XtraUserControlKira
    {

        #region Variable

        private Dao dao;
        private order _order;

        #endregion

        public Frm_Sales_Return()
        {
            InitializeComponent();
            FormCode = EnumFormCode.FrmReturnSale;
            buttonsArray1.capQuyen(new Permission(FormCode.ToString(), ClsPublic.User.User_Username));
            dao = new Dao(true, true);

        }



        #region Button event

        private void buttonsArray1_btnEventClose_click(object sender, System.EventArgs e)
        {
            this.Dispose();
        }

        private void buttonsArray1_btnEventSave_click(object sender, System.EventArgs e)
        {

        }

        private void buttonsArray1_btnEventPrint_click(object sender, System.EventArgs e)
        {

        }

        #endregion


        #region Grid event



        #endregion


        #region Control event


        private void txtOrderCode_EditValueChanged(object sender, System.EventArgs e)
        {
            LoadForm();
        }

        #endregion


        #region Method

        public override bool update()
        {

            return base.update();
        }

        public override void LoadForm()
        {
            if (Regex.IsMatch(txtOrderCode.EditValue + string.Empty, "[A-Z]{2}-[0-9]{6}-[0-9]{4}"))
            {
                //string dateExpired = ClsPublic.
                var listOrder = dao.FindByMultiColumnAnd<order>(new[] { "code" }, txtOrderCode.EditValue);
                if (listOrder.Count > 0)
                {
                    _order = listOrder.First();
                    gridControl1.DataSource = _order.orders_details;
                }
            }
            base.LoadForm();
        }

        #endregion

        

























    }
}
